# 练习1：
# 定义一个类
# 该类具有x和y两个属性，
# 定义构造函数初始化这两个属性。
# 类中还定义以下方法：
# 类中提供max()、min()、sum()与average()
# 求两个数的和(x+y)并返回结果的方法，
# 求两个数的差(x-y)并返回结果的方法，
# 求两个数的乘(x*y)并返回结果的方法，
# 求两个数的商(x/y)并返回结果的方法，
# 求两个数的余(x%y)并返回结果的方法，
# 编写应用程序，测试上面定义的类，
# 使用类中定义的各个方法并将其结果输出。

# class Function():
#     def __init__(self,x=5,y=2):
#         self.x = x
#         self.y = y
#     def max(self):
#         i = 0
#         if self.x > self.y :
#             i = self.x
#         else:
#             i = self.y
#         return f'最大数为：{i}'
#     def min(self):
#         i = 0
#         if self.x < self.y:
#             i = self.x
#         else:
#             i = self.y
#         return f'最小数为：{i}'
#     def average(self):
#         return f'两数平均值为：{(self.x+self.y)/2}'
#     def sum(self):
#         return f'两数之和为：{self.x+self.y}'
#     def subtraction(self):
#         return f'两数之差为：{self.x-self.y}'
#     def product(self):
#         return f'两数之积为：{self.x*self.y}'
#     def division(self):
#         return f'两数之商为：{self.x/self.y}'
#     def remainder(self):
#         return f'两数之余数为：{self.x % self.y}'
#
# number = Function()
# number.x = 3
# number.y = 4
#
# print(number.max())
# print(number.min())
# print(number.average())
# print(number.sum())
# print(number.subtraction())
# print(number.product())
# print(number.division())
# print(number.remainder())

# 练习2
# 设计一台Android手机，有3种不同颜色，
# 屏幕尺寸是3.5英寸，内存16G，4核2.5G处理器，
# 有播放音乐，看电影，写邮件，拍照片功能。
#
# 定义类，并创建一台手机，打印这台手机，并调用功能
class Mobilephone():
    def __init__(self,x='蓝色',y='黑色',z='白色'):
        self.x = x
        self.y = y
        self.z = z
    def phone_attribute(self):
        print('屏幕尺寸是3.5英寸，内存16G，4核2.5G处理器')
    def playmusic(self):
        print('播放音乐')
    def watchmovie(self):
        print('看电影')
    def email(self):
        print('写邮件')
    def picture(self):
        print('拍照片')
    def __str__(self):
        return '屏幕尺寸是3.5英寸，内存16G，4核2.5G处理器'
#
# phone = Mobilephone()
# phone.x = '蓝色'
#
# phone.phone_attribute()
# phone.playmusic()
# phone.watchmovie()
# phone.email()
# phone.picture()
#
# print(phone)


# 练习3
# 定义一个猜数字游戏类
# 定义一个变量用来存储数字，初始化的时候随机给个1~100的值
# 提供一个方法传入一个数值，返回1 -1 0 表示大了 小了 相等
# 用以下代码测试
import random
class Game():
    def __init__(self,computer_number=random.randint(1,100)):
        self.player_number = 0

    def game_ratiosize(self,computer_number=random.randint(1,100)):
        x = computer_number
        if self.player_number > x:
            print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为1，表示玩家的数更大')
        elif self.player_number < x:
            print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为-1，表示玩家的数更小')
        else:
            print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为0，表示玩家的数和电脑的数相等')

player = Game()
player.player_number = 3
player.game_ratiosize()

class GuessNumberSystem():
    def __init__(self,computer_number=random.randint(1,100)):
        self.player_number = 0

    # def game_ratiosize(self,computer_number=random.randint(1,100)):
    #     x = computer_number
    #     if self.player_number > x:
    #         y = 1
    #         print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为1，表示玩家的数更大')
    #     elif self.player_number < x:
    #         y = -1
    #         print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为-1，表示玩家的数更小')
    #     else:
    #         y = 0
    #         print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为0，表示玩家的数和电脑的数相等')
    def __str__(self):
        def game_ratiosize(self, computer_number=random.randint(1, 100)):
            x = computer_number
            if self.player_number > x:
                y = 1
                print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为1，表示玩家的数更大')
            elif self.player_number < x:
                y = -1
                print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为-1，表示玩家的数更小')
            else:
                y = 0
                print(f'玩家的数为：{self.player_number},电脑的数为：{x},返回值为0，表示玩家的数和电脑的数相等')
        








game = GuessNumberSystem()
# while True:
#     n = int(input("请输入一个数:"))
#     result = game.guess(n)
#     if result==1:
#         print("大了")
#     elif result==-1:
#         print("小了")
#     else:
#         print("猜中了")
#         break
#
# # 4. 编写一个累计计算器,内置一个变量
# c = Calc()
# c.add(5)
# print(c) #打印输出5
# c.sub(3)
# print(c) #打印输出2
# c.mul(2)
# print(c) #应输出4
# c.div(2)
# print(c) # 输出1
# c.clear()
# print()  # 输出0